/**
 * Created by pjn on 2017/8/11.
 */
//窨井故障类型
var faultType = [{"value": "0", "name": "损毁"}, {"value": "1", "name": "其他"}];

var acReport = 0;
var acAudit = 0;
var acAdmin = 0;
var actorId = 0;
var isAdd = false;

var mData;//地图标点
var startRoad4S = "";
var endRoad4S = "";
var roadName4S = "";
var userMobile = "";
var coverMainOrgId = 0;
var coverOrgId = 0;
var solarEId = 0;//地图确定点标志位


$.getActorId = function (data) {
    var actorId = 0;
    if (data.indexOf("6") >= 0) {
        actorId = 6;
        acReport = 1;
    }
    if (data.indexOf("3") >= 0) {
        actorId = 3;
        acAudit = 1;
    }
    if (data.indexOf("1") >= 0) {
        actorId = 1;
        acAdmin = 1;
    }
    return actorId;
};
actorId = $.getActorId(gUserLoginResult.userActors);
console.log(gUserLoginResult.userActors);

$(function () {
    gMainDT = $("#mainDataTables").DataTable({
        ajax: {
            url: "../rds_coverFault/getCoverReportFault4DT",
            type: "POST",
            data: function (d) {
                d.search = $('#mainDataTables').DataTable().search(this.value);
                d.actorId = actorId;
                d.orgId = gUserLoginResult.orgId;
                d.userId = gUserLoginResult.userId;
            }
        },
        columns: [{
            data: "coverFaultId",
            render: function (data, type, row, meta) {
                var checkId = "checkbox" + (parseInt(meta.row) + 1);
                return "<input type='checkbox' data-status='" + row.coverCheck + "' value='" + data + "' id='" + checkId + "'>";
            }
        }, {
            data: "coverFaultId",
            targets: 0
        }, {
            data: "coverPhoto",
            render: function (data, type, row) {
                return "<img src='" + data + "' style='width:50px;height:40px;cursor: pointer' " +
                    "onclick='$.showPicModal(\"" + data + "\")'> ";
            }
        }, {
            data: "coverFaultCreatorName"
        }, {
            data: "coverFaultTime",
            render: function (data, type, row, meta) {
                return data.substring(0, 10);
            }
        }, {
            data: "coverOrgName"
        }, {
            data: "coverCheckerName",
            render: function (data, type, row) {
                if (data == "" || data == null) {
                    return "暂未审核"
                } else {
                    return data
                }
            }
        }, {
            data: "coverId",
            render: function (data, type, row) {
                return "<button class='btn btn-primary btn-xs btn-flat' onclick='$.coverDetails (" + JSON.stringify(row) + ",0)' title='窨井详情'>点击查看</button>";
            }
        }, {
            data: "coverFaultId",
            render: function (data, type, row) {
                return "<button class='btn btn-primary btn-xs btn-flat' onclick='$.coverFaultDetails (" + JSON.stringify(row) + ")' title='窨井故障详情'>点击查看</button>";
            }
        }, {
            data: "coverFaultId",
            render: function (data, type, row) {
                var allData = JSON.stringify(row).replace(/\'/g, "&apos;");
                // 左侧工具栏按钮的权限
                // var buttonInsert = "<button class='btn btn-info btn-xs btn-flat' onclick='$.addFaultReport()' title='添加'><i class='fa fa-plus-square'></i></button>";
                var buttonAudit = "", buttonUpdate = "", buttonOperation = "";
                if (acAudit == 1 || acAdmin == 1 || acReport == 1) {
                    if (row.coverCheck == 0 && (acAudit == 1 || acAdmin == 1))
                        buttonAudit = "<button  class='btn btn-primary btn-xs btn-flat'  onclick='$.showCoverFaultCheckModal(" + allData + ")'><span class='glyphicon glyphicon-check' aria-hidden='true' ></span>上报</button>";
                    if (row.coverCheck == -1)
                        buttonAudit = "<button onclick='$.faultInfoDetails(" + allData + "," + row.coverCheck + "," + row.coverMainCheck + "," + row.coverMaintenanceStatus + ")' class='btn btn-danger btn-xs btn-flat'>未上报</button>";
                    if (row.coverCheck == 1)
                        buttonAudit = "<button onclick='$.faultInfoDetails(" + allData + "," + row.coverCheck + "," + row.coverMainCheck + "," + row.coverMaintenanceStatus + ")' class='btn btn-success btn-xs btn-flat'>已上报</button>";
                    else if (row.coverCheck == 2)
                        buttonAudit = "<button onclick='$.faultInfoDetails(" + allData + "," + row.coverCheck + "," + row.coverMainCheck + "," + row.coverMaintenanceStatus + ")' class='btn btn-warning btn-xs btn-flat'>已通过</button>";
                    buttonOperation += buttonAudit;
                }
                if (row.coverCheck != 0)
                    buttonUpdate = "<button class='btn btn-primary btn-xs btn-flat' disabled='disabled' title='编辑'><i class='fa fa-edit'></i></button>";
                else
                    buttonUpdate = "<button class='btn btn-primary btn-xs btn-flat' onclick='$.updateCoverFault(" + allData + ")' title='编辑'><i class='fa fa-edit'></i></button>";
                if (acReport == 1 || acAdmin == 1)
                    buttonOperation += "&nbsp&nbsp&nbsp&nbsp" + buttonUpdate;
                return buttonOperation;
            }
        }],
        dom: "<'row'<'col-md-4'l><'#mainToolbar.col-md-8'>r>t<'row'<'col-md-6'i><'#setZ-index.col-md-6'p>>",
        initComplete: function () {
            // 下拉工具栏按钮的权限
            $("#mainToolbar").empty();
            var strToolBar = "<div class='btn-group'><button type='button' class='btn btn-primary btn-sm btn-flat'><i class='fa fa-cog'></i> 操作</button>";
            strToolBar += "<button type='button' class='btn btn-primary btn-sm btn-flat dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>";
            strToolBar += "<span class='caret'></span><span class='sr-only'>切换下拉</span></button><ul class='dropdown-menu'>";
            strToolBar += "<li><button href='#' class='btn btn-primary btn-sm btn-flat btn-block' onclick='gMainDT.ajax.reload(null, false);'><i class='fa fa-reFaultReportesh'></i> 刷新</button></li>";
            var buttonInsert = "<button style='margin-right: 3px;' type='button' class='btn btn-primary btn-sm btn-flat' onclick='$.addCoverFault()'><i class='fa fa-plus-square'></i> 故障申报</button>";
            // 下拉工具栏不处理更新事件，但今后可能需要审核等功能，替换该位置即可
            //var buttonUpdate = "<li><button href='#' class='btn btn-warning btn-sm btn-flat btn-block' onclick='$.updateFaultReport()'><i class='fa fa-edit'></i> 编辑</button></li>";
            var buttonDelete = "<li><button href='#' class='btn btn-primary btn-sm btn-flat btn-block' onclick='$.deleteCoverFaultReport()'><i class='fa fa-minus-square'></i> 删除</button></li>";
            gInsert == 0 ? strToolBar : strToolBar = buttonInsert + strToolBar;
            if (acReport == 1 || acAdmin == 1) {
                strToolBar += buttonDelete;
            }
            strToolBar += "</ul></div> <div style='z-index: 0' class='input-group input-group-sm'><input type='text' class='form-control' name='searchText' placeholder='路'>";
            strToolBar += "<span class='input-group-btn'><button class='btn btn-primary btn-flat' type='button' onclick='$(this).searchDT()'><i class='fa fa-search'></i></button></span></div></div>";
            strToolBar = "<div class='pull-right'>" + strToolBar;
            $("#mainToolbar").append(strToolBar);
        },
        processing: true,
        serverSide: true,
        ordering: false,
        select: false,
        autoFill: true,
        displayLength: 20,
        lengthMenu: [[5, 10, 15, 20, 50, 100, 150, -1], [5, 10, 15, 20, 50, 100, 150, "All"]],
        language: {
            url: "zh_cn.json"
        },
        fnDrawCallback: function () {// 序号自增回调函数
            var api = this.api();
            var startIndex = api.context[0]._iDisplayStart;
            api.column(1).nodes().each(function (cell, i) {
                cell.innerHTML = startIndex + i + 1;
            });
        }
    });

    //故障类型初始化(上报时)
    var faultTypeInit = "";
    for (var i = 0; i < faultType.length; i++) {
        faultTypeInit += "<option value='" + faultType[i].value + "'>" + faultType[i].name + "</option>";
    }
    $("#addFault_faultType").append(faultTypeInit);
});

// 搜索框查询操作
$.fn.searchDT = function () {
    // 注意gSelect查询权限的处理，由该表是否存在添加人或者审核人决定
    var searchContext = $("input[name='searchText']").val();
    gMainDT.search(searchContext).draw();
};

// DT头部的复选按钮全选操作
$.checkChange = function () {
    var isChecked = $("#batch_check").prop('checked');
    $("input[type='checkbox']").prop("checked", isChecked);
};

$.faultInfoDetails = function (jsonData, orgCheck, mainCheck, maintenanceStatus) {
    var status = -1;
    $(".ystep2").empty();
    $(".ystep2").loadStep({
        size: "large",
        color: "green",
        steps: [{
            title: "故障申报"
        }, {
            title: "内部审核"
        }, {
            title: "上报监管单位"
        }, {
            title: "监管单位审核"
        }, {
            title: "故障处理"
        }, {
            title: "故障完成"
        }]
    });
    //初始化
    $("#operationRecord").html("<tr>\n" +
        "                            <th>环节名称</th>\n" +
        "                            <th>到达时间</th>\n" +
        "                            <th>处理时间</th>\n" +
        "                            <th>处理人</th>\n" +
        "                            <th>操作类型</th>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>故障申报</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>内部审核</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>上报监管单位</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                            <td>--</td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>监管单位审核</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>\n" +
        "                        <tr>\n" +
        "                            <td>故障处理</td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                            <td></td>\n" +
        "                        </tr>");
    $.ystepTest(jsonData, orgCheck, mainCheck, maintenanceStatus);
    // $.setOperationRecord(jsonData);

    $("#modal-signFaultStatus").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
};


$.ystepTest = function (jsonData, orgCheck, mainCheck, maintenanceStatus) {
    var $list = $("#operationRecord tr");
    var $tr = [], i = 0;
    for (i = 0; i < $list.length; i++) {
        $tr.push($list.eq(i).find("td"))
    }
    $tr[1].eq(1).html(jsonData.coverFaultTime);
    $tr[1].eq(3).html(jsonData.coverFaultCreatorName);
    $tr[2].eq(1).html(jsonData.coverFaultTime);
    $tr[2].eq(2).html(jsonData.coverCheckTime);
    $tr[2].eq(3).html(jsonData.coverCheckerName);
    switch (orgCheck) {
        case 0://待内部审核
            $(".ystep2").setStep(2);
            break;
        case -1://内部拒绝
            $(".ystep2").setStep(2, 2);
            $tr[2].eq(4).html("拒绝");
            break;
        case 1://内部通过
            $tr[2].eq(4).html("同意");
            $tr[4].eq(1).html(jsonData.coverCheckTime);
            switch (mainCheck) {
                case 0: //待主管
                    $(".ystep2").setStep(3);
                    break;
                case -1://主管拒绝
                    $(".ystep2").setStep(4, 4);
                    $tr[4].eq(2).html(jsonData.coverMainCheckTime);
                    $tr[4].eq(3).html(jsonData.coverMainCheckerName);
                    $tr[4].eq(4).html("拒绝");

                    break;
                case 1:
                    $tr[4].eq(2).html(jsonData.coverMainCheckTime);
                    $tr[4].eq(3).html(jsonData.coverMainCheckerName);
                    $tr[4].eq(4).html("同意");
                    $tr[5].eq(1).html(jsonData.coverMainCheckTime);
                    switch (maintenanceStatus) {
                        case 1: //待维修
                            $(".ystep2").setStep(4);
                            break;
                        case 2://维修完成
                            $tr[5].eq(2).html(jsonData.coverMaintenanceTime);
                            $tr[5].eq(3).html(jsonData.coverMaintainerName);
                            $tr[5].eq(4).html("完成施工");
                            $(".ystep2").setStep(6);
                            break;
                    }
                    //主管通过
                    break;
            }
            break;
        case 2://跳过主管
            $tr[2].eq(4).html("内部同意");
            $tr[4].eq(1).html("--");
            $tr[4].eq(2).html("--");
            $tr[4].eq(3).html("--");
            $tr[4].eq(4).html("--");
            $tr[5].eq(1).html(jsonData.coverMainCheckTime);
            switch (maintenanceStatus) {
                case 1://待维修
                    $(".ystep2").setStep(5, [3, 4]);
                    break;
                case 2://维修完成
                    $tr[5].eq(2).html(jsonData.coverMaintenanceTime);
                    $tr[5].eq(3).html(jsonData.coverMaintainerName);
                    $tr[5].eq(4).html("完成施工");
                    $(".ystep2").setStep(6, [3, 4]);
                    break;
            }
            break;
    }
};

//获取用户电话
$.ajax({
    url: "../rds_user/getUserById",
    type: "POST",
    async: false,
    data: {
        userId: gUserLoginResult.userId
    },
    success: function (msg) {
        if (msg != null && typeof(msg) != "undefined") {
            if (msg.isSuccess == true) {
                userMobile = msg.jsonData.userMobile;
            } else {
                $.alert("系统错误", 2);
            }
        }
    }
});
//确定是否能上报
$.getFaultIsReport = function (data) {
    $.ajax({
        url: "../rds_coverFault/getCoverFaultIsReport",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: data
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    if (msg.jsonData == 1) {
                        $("#detail_reportbtn").attr("title", "");
                        $("#detail_reportbtn").attr("disabled", false);
                    } else {
                        $("#detail_reportbtn").attr("title", "该窨井正在处理中，无法上报");
                        $("#detail_reportbtn").attr("disabled", true);
                    }
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};

//窨井详情
$.coverDetails = function (data, status) {
    if (status == 1) {//1是地图
        solarEId = data.coverId;//地图确定用
        $("#detail_reportbtn").css("display", "block");
        $.getFaultIsReport(data.coverId);
    }
    if (data.coverPhoto != "" && data.coverPhoto != null) {
        $("#detail_photo").attr("src", data.coverPhoto);
    }
    else {
        $("#detail_photo").attr("src", "../images/default_photo.png");
    }
    $.ajax({
        url: "../rds_coverFault/getCoverInfo2Fault",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: data.coverId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    $("#detail_province").val(msg.jsonData.coverProvince);
                    $("#detail_city").val(msg.jsonData.coverCity);
                    $("#detail_area").val(msg.jsonData.coverArea);
                    $("#detail_coordinate").val(msg.jsonData.coverLongitude + "," + msg.jsonData.coverLatitude);
                    $("#detail_mainOrgName").val(msg.jsonData.coverMainOrgName);
                    $("#detail_orgName").val(msg.jsonData.coverOrgName);
                    $("#detail_creatorName").val(msg.jsonData.coverCreatorName);
                    $("#detail_roadName").val(msg.jsonData.coverRoadName);
                    $("#detail_startRoad").val(msg.jsonData.coverStartRoad);
                    $("#detail_endRoad").val(msg.jsonData.coverEndRoad);
                    $("#detail_installOrg").val(msg.jsonData.coverInstallOrg);
                    $("#detail_shape").val(msg.jsonData.coverShape);
                    $("#detail_serviceLife").val(msg.jsonData.coverServiceLife + "年");
                    $("#detail_CoverMaterial").val(msg.jsonData.coverMaterial);

                    $("#detailInfoModalLabel").text("窨井详情");
                    $("#detailInfoModal").modal({
                        backdrop: 'static',
                        keyboard: false,
                        show: true
                    });
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};

//详情地图显示
$(".myBtnUpdate").click(function () {
    var coordinate = $("#detail_coordinate").val().split(",");
    var url = "fault/roadPoleAuditMap.html";
    url += "?x=" + coordinate[0] + "&y=" + coordinate[1] + "&z=1";//通过这种方式传参数
    $("#myMap").attr("src", url);
    $("#modal-map").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    })
});

//故障详情
$.coverFaultDetails = function (data) {
    isAdd = false;
    $.ajax({
        url: "../rds_coverFault/getCoverFaultInfo2Fault",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: data.coverId,
            coverFaultId: data.coverFaultId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var data = msg.jsonData;
                    $("#addFault_roadName").text(data.coverRoadName);
                    $("#addFault_address").text(data.coverProvince + "" + data.coverCity + ""
                        + data.coverArea + " " + data.coverStartRoad + "(起)--" + data.coverEndRoad + "(止)");
                    $("#addFault_faultPhoto").attr("src", data.coverFaultPhoto);
                    $("#addFault_money").val(data.coverMoney);
                    $("#addFault_faultType").val(data.coverFaultType);
                    $("#addFault_faultLevel").val(data.coverFaultLevel);
                    $("#addFault_faultReason").val(data.coverFaultReason);
                    $("#addFault_creatorName").text(data.coverFaultCreatorName);
                    $("#addFault_creatorPhone").text(data.coverFaultCreatorPhone);

                    $("#addFault_money").attr("disabled", true);
                    $("#addFault_faultType").attr("disabled", true);
                    $("#addFault_faultLevel").attr("disabled", true);
                    $("#addFault_faultReason").attr("disabled", true);
                    $("#addFault_faultPhoto").attr("onclick", "");
                    $("#reportBtn").hide();
                    $("#addFault_DTBtn").hide();
                    $("#addFault_signMapBtn").hide();

                    $("#addFaultModalLabel").text("窨井故障详情");
                    $("#addFaultModal").modal({
                        backdrop: 'static',
                        keyboard: false,
                        show: true
                    });
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};

//审核
$.showCoverFaultCheckModal = function (data) {
    coverOrgId = data.coverOrgId;
    coverMainOrgId = data.coverMainOrgId;
    $("#straight-button").attr("disabled", false);
    $("#ac-button").attr("disabled", false);
    $("#notac-button").attr("disabled", false);
    $("#audit_faultId").text(data.coverFaultId);
    $.ajax({
        url: "../rds_coverFault/getCoverFaultInfo2Fault",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: data.coverId,
            coverFaultId: data.coverFaultId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var data = msg.jsonData;
                    $("#audit_faultPhoto").attr("src", data.coverFaultPhoto);
                    $("#audit_faultType").html(faultType[data.coverFaultType].name);
                    $("#audit_faultCreatorName").html(data.coverFaultCreatorName);
                    $("#audit_faultTime").html(data.coverFaultTime.substring(0, 10));
                    $("#audit_faultMoney").html(data.coverMoney);
                    $("#audit_faultFeedback").removeAttr("readOnly");
                    $("#audit_faultReason").html(data.coverFaultReason);
                    $("#audit_faultLevel").html($.getSignFaultLevelCN(data.coverFaultLevel));

                    var url = "fault/map.html";
                    url += "?x=" + msg.jsonData.coverLongitude + "&y=" + msg.jsonData.coverLatitude + "";//通过这种方式传参数
                    $("#audit_faultMap").attr("src", url);

                    $("#auditModalLabel").text("窨井故障审核");
                    $("#auditModal").modal({
                        backdrop: 'static',
                        keyboard: false,
                        show: true
                    });
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};
//审核窗口的故障等级
$.getSignFaultLevelCN = function (faultLevel) {
    var str = "";
    switch (faultLevel) {
        case 1:
            str = "一级";
            break;
        case 2:
            str = "二级";
            break;
        case 3:
            str = "三级";
            break;
        case 4:
            str = "四级";
            break;
        case 5:
            str = "五级";
            break;
    }
    return str;
};
$("#audit_faultFeedback").focus(function () {
    $("#straight-button").attr("disabled", false);
    $("#ac-button").attr("disabled", false);
    $("#notac-button").attr("disabled", false);
});

$("#straight-button").click(function () {
        $("#straight-button").attr("disabled", true);
        $("#ac-button").attr("disabled", true);
        $("#notac-button").attr("disabled", true);
        $.faultAudit(2);
    }
);

//点击通过按钮
$("#ac-button").click(function () {
        $("#straight-button").attr("disabled", true);
        $("#ac-button").attr("disabled", true);
        $("#notac-button").attr("disabled", true);
        if (coverOrgId == coverMainOrgId) {
            $.alert("没有选择监管单位", 2);
        } else
            $.faultAudit(1);
    }
);
//点击不通过按钮
$("#notac-button").click(function () {
    $("#straight-button").attr("disabled", true);
    $("#ac-button").attr("disabled", true);
    $("#notac-button").attr("disabled", true);
    $.faultAudit(-1);
});
//审核操作
$.faultAudit = function (ispass) {
    var feedback = $("#audit_faultFeedback").val();
    if (feedback == "" && ispass == -1) {
        $.alert('请填写故障反馈', 2);
    } else {
        $.ajax({
            url: "../rds_coverFaultCheck/coverFaultAudit",
            type: 'post',
            data: {
                userDevice: 'web',
                isPass: ispass,
                feedback: feedback,
                coverFaultId: $("#audit_faultId").html(),
                userId: gUserLoginResult.userId
            },
            dataType: 'json',
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        $.alert("审核成功", 1);
                        $.closeAuditModal();
                        gMainDT.ajax.reload(null, false);
                    } else
                        $.alert("修改失败！", 2);
                } else {
                    $.alert('系统错误', 2);
                }


            },
            error: function (data) {
                $.alert("系统错误", 2);
            }
        })
    }
};

//编辑故障上报
$.updateCoverFault = function (data) {
    isAdd = true;
    $("#addFault_coverId").val(data.coverId);
    $("#addFault_coverFaultId").val(data.coverFaultId);
    $.ajax({
        url: "../rds_coverFault/getCoverFaultInfo2Fault",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: data.coverId,
            coverFaultId: data.coverFaultId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var data = msg.jsonData;
                    $("#addFault_roadName").text(data.coverRoadName);
                    $("#addFault_address").text(data.coverProvince + "" + data.coverCity + ""
                        + data.coverArea + " " + data.coverStartRoad + "(起)--" + data.coverEndRoad + "(止)");
                    $("#addFault_faultPhoto").attr("src", data.coverFaultPhoto);
                    $("#addFault_money").val(data.coverMoney);
                    $("#addFault_faultType").val(data.coverFaultType);
                    $("#addFault_faultLevel").val(data.coverFaultLevel);
                    $("#addFault_faultReason").val(data.coverFaultReason);
                    $("#addFault_creatorName").text(data.coverFaultCreatorName);
                    $("#addFault_creatorPhone").text(data.coverFaultCreatorPhone);

                    $("#reportBtn").hide();
                    $("#updateBtn").show();
                    $("#addFault_DTBtn").hide();
                    $("#addFault_signMapBtn").hide();

                    $("#addFaultModalLabel").text("窨井故障编辑");
                    $("#addFaultModal").modal({
                        backdrop: 'static',
                        keyboard: false,
                        show: true
                    });
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
};
//保存编辑
$.updateFault = function () {
    var money = $("#addFault_money").val();
    if (money == "") {
        money = 0.00;
    }
    if ($("#addFault_address").text() == "" && $("#addFault_roadName").text() == "") {
        $.alert("请选择窨井", 2);
    } else if ($("#addFault_faultReason").val() == "") {
        $.alert("请填写故障原因", 2);
    } else {
        $.ajax({
            url: "../rds_coverFault/updateCoverFault",
            type: 'post',
            data: {
                coverFaultId: $("#addFault_coverFaultId").val(),
                coverFaultLevel: $("#addFault_faultLevel").val(),
                coverFaultType: $("#addFault_faultType").val(),
                coverFaultPhoto: $("#addFault_faultPhoto").attr("src"),
                coverFaultReason: $("#addFault_faultReason").val(),
                coverMoney: money
            },
            dataType: 'json',
            success: function (msg) {
                if (msg.isSuccess == true) {
                    $.alert("保存成功", 1);
                    gMainDT.ajax.reload(null, false);
                    $.closeAddFaultModal();
                } else {
                    $.alert("数据操作失败", 2);
                }
            },
            error: function (msg) {
                $.alert('系统错误，请联系管理员', 2);
            }
        });
    }
};


//删除故障
$.deleteCoverFaultReport = function () {
    var deleteStatus = 0;//判断是否可以删除 0可以删
    var count = $("input:checkbox[id^='checkbox']:checked").length;
    if (count == 0) {
        $.alert("请选择要删除的数据", 2);
        return;
    } else {
        var faultIds = "";
        $("input:checkbox[id^='checkbox']:checked").each(function () {
            faultIds += $(this).val() + ",";
            var faultCheck = $(this).attr("data-status");
            if (faultCheck != 0 && faultCheck != -1) {
                deleteStatus = 1;
            }
        });
        faultIds = faultIds.substring(0, faultIds.length - 1);
    }
    if (deleteStatus == 1) {
        $.alert("故障已上报，无法删除", 2);
    } else {
        bootbox.confirm({
            buttons: {
                confirm: {
                    label: '<i class="fa fa-check"></i> 确定',
                    className: 'btn btn-primary btn-flat'
                },
                cancel: {
                    label: '<i class="fa fa-close"></i> 取消',
                    className: 'btn btn-warning btn-flat pull-left'
                }
            },
            message: '<i class="fa fa-question-circle-o"></i> <b class="customer-title">确定删除该' + count + '条数据吗?</b>',
            callback: function (result) {
                if (result) {
                    $.ajax({
                        url: '../rds_coverFault/deleteCoverFaultByIds',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            "coverFaultIds": faultIds
                        },
                        success: function (msg) {
                            if (msg != null && typeof (msg) != "undefined") {
                                if (msg.isSuccess == true) {
                                    if (msg.jsonData > 0) {
                                        $.alert("数据删除成功", 1);
                                        gMainDT.ajax.reload(null, false);
                                    } else {
                                        $.alert("数据删除失败", 2);
                                    }
                                } else {
                                    $.alert("数据删除失败", 2);
                                }
                            } else {
                                $.alert('系统错误，请联系管理员', 2);
                            }
                        },
                        error: function (msg) {
                            $.alert('系统错误，请联系管理员', 2);
                        }
                    });
                }
            }
        });
    }
};

//添加窨井故障
$.addCoverFault = function () {
    isAdd = true;
    $("#addFault_creatorName").text(gUserLoginResult.userName);
    $("#addFault_creatorPhone").text(userMobile);

    $("#addFaultModalLabel").text("上报窨井故障");
    $("#reportBtn").attr("disabled", false);
    $("#addFaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

//选择地图Modal
$.selectMap = function () {
    $("#addFaultModal").modal("hide");
    $("#selectMap").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
    $(".modal-backdrop").attr("style", "z-index:-1");
    $(".paginate_button").attr("style", "z-index:0");

    setTimeout(function () {
        $.init_Map();
    }, 200);

};
$.init_Map = function () {
    function initMap() {
        createMap();//创建地图
        setMapEvent();//设置地图事件
        addMapControl();//向地图添加控件
    }

    $.getCoordinate = function () {
        $.ajax({
            url: "../rds_coverFault/getCoverCoordinate4Map",
            type: 'post',
            async: false,
            dataType: 'json',
            data: {
                "orgId": gUserLoginResult.orgId,
                "actorId": actorId
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        mData = msg.jsonData;
                    }
                }
            }
        });
    };

    //创建地图函数：
    function createMap() {
        //$("#dituContent").css("height", midHeight);
        map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
        map.centerAndZoom(gPoint, 13);//设定地图的中心点和坐标并将地图显示在地图容器中
        $.getCoordinate();
        $.drawPiont();
    }

    $.drawPiont = function () {
        if (document.createElement('canvas').getContext) {  // 判断当前浏览器是否支持绘制海量点
            var points = [];  // 添加海量点数据
            for (var i = 0; i < mData.length; i++) {
                points.push(new BMap.Point(mData[i].coverLongitude, mData[i].coverLatitude));
            }
            var options = {
                size: 6,
                shape: 1,
                color: '#d3140d'
            };
            pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection
            map.addOverlay(pointCollection);  // 添加Overlay
        } else {
            alert('请在chrome、safari、IE8+以上浏览器查看本示例');
        }
    };

    //地图事件设置函数：
    function setMapEvent() {
        map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.disableDoubleClickZoom();//禁用鼠标双击放大
        map.enableKeyboard();//启用键盘上下左右键移动地图
    }

    //地图控件添加函数：
    function addMapControl() {
        //向地图中添加缩放控件
        var ctrl_nav = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE});
        map.addControl(ctrl_nav);

        //向地图中添加比例尺控件
        var ctrl_sca = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, enableGeolocation: true});
        map.addControl(ctrl_sca);

        var geolocationControl = new BMap.GeolocationControl();
        geolocationControl.addEventListener("locationSuccess", function (e) {

        });
        geolocationControl.addEventListener("locationError", function (e) {
            // 定位失败事件
            alert(e.message);
        });
        map.addControl(geolocationControl);


    }

    function G(id) {
        return document.getElementById(id);
    }

    initMap();//创建和初始化地图

    var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
        {
            "input": "suggestId"
            , "location": map
        });
    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G("searchResultPanel").innerHTML = str;
    });

//搜索
    var myValue;
    ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
        var _value = e.item.value;
        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
        G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        setPlace();
    });

    $("#search-button").click(function () {
        myValue = $("#suggestId").val();
        setPlace();
    });

    $("#suggestId").keydown(function (event) {
        if (event.keyCode == 13) {
            myValue = $("#suggestId").val();
            setPlace();
        }
    });

    function setPlace() {
        // map.clearOverlays();   //清除地图上所有覆盖物
        //$.drawPiont();
        function myFun() {
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 15);
            //  map.addOverlay(new BMap.Marker(pp));    //添加标注
        }

        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }

    pointCollection.addEventListener('mouseover', function (e) {
        var info = "";
        var x = formatXY(e.point.lng);
        var y = formatXY(e.point.lat);


        $.ajax({
            url: "../rds_coverFault/getCoverByXY",
            type: 'post',
            // async: false,
            dataType: 'json',
            data: {
                "longitude": x,
                "latitude": y
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess) {
                        var data = msg.jsonData[0];
                        info = "<div style='text-align:center'><img style='height: 200px' src=" + data.coverPhoto + ">" +
                            "<p>地址：" + data.coverProvince + ' ' + data.coverCity + " " + data.coverArea + "</p>" +
                            "<p>" + data.coverRoadName + "" + data.coverStartRoad + '(起)' + data.coverEndRoad + "(止)</p>" +
                            "<button style='float: right' onclick='$.coverDetails(" + JSON.stringify(data) + ",1)'>" +
                            "<i class='glyphicon glyphicon-option-horizontal'></i></button>" +
                            "</div>";
                        var opt = {
                            width: 200
                        };
                        var infoWindow = new BMap.InfoWindow(info, opt);  // 创建信息窗口对象
                        map.openInfoWindow(infoWindow, e.point); //开启信息窗口
                    } else {
                        $.alert("信息获取失败", 2);
                    }
                } else {
                    $.alert("信息获取失败", 2);
                }
            }
        });

    });

    function formatXY(n) {
        var number = n + "",
            point = number.indexOf("."),
            len = number.length, len2 = len - point - 1;
        for (; len2 < 6; len2++) {
            number += "0";
        }
        return number;
    }
};

//确定故障上报的窨井
$.sureCover = function (coverId) {
    if (coverId == 0) {
        coverId = solarEId;
    }
    $("#addFault_coverId").val(coverId);
    $.ajax({
        url: "../rds_coverFault/getCoverInfo2Fault",
        type: 'post',
        async: true,
        data: {
            userDevice: 'web',
            coverId: coverId
        },
        dataType: 'json',
        success: function (msg) {
            if (msg != null && typeof (msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var data = msg.jsonData;
                    $("#addFault_roadName").text(data.coverRoadName);
                    $("#addFault_address").text(data.coverProvince + "" + data.coverCity + ""
                        + data.coverArea + " " + data.coverStartRoad + "(起)--" + data.coverEndRoad + "(止)");
                    $("#addFault_faultPhoto").attr("src", data.coverPhoto);
                    $("#addFault_coverOrgId").val(data.coverOrgId);
                    $("#addFault_coverMainOrgId").val(data.coverMainOrgId);
                } else
                    $.alert("数据获取失败！", 2);
            } else {
                $.alert('系统错误', 2);
            }
        },
        error: function (data) {
            $.alert("系统错误", 2);
        }
    });
    solarEId = 0;
    $("#detail_reportbtn").css("display", "none");
    $("#detailInfoModal").modal("hide");
    $("#coverDTModal").modal("hide");
    //$("#showReasonModal").modal("hide");
    $("#selectMap").modal("hide");//隐藏地图
    $("#addFaultModal").show();
    $("#addFaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

//显示窨井datatable modal
$.coverDTModal = function () {
    //actor 可能为3,由于根据orgId.无妨
    startRoad4S = "";
    endRoad4S = "";
    roadName4S = "";
    gReportMainDT = $("#coverDTDataTables").DataTable({
        ajax: {
            url: "../rds_coverFault/getCoverFaultReport4DT",
            type: "POST",
            data: function (d) {
                d.search = $('#coverDTDataTables').DataTable().search(this.value);
                d.orgId = gUserLoginResult.orgId;
                d.actorId = actorId;
                d.coverRoadName = roadName4S;
                d.coverStartRoad = startRoad4S;
                d.coverEndRoad = endRoad4S;
            }
        },
        columns: [{
            data: "coverId",
            targets: 0
        }, {
            data: "coverPhoto",
            render: function (data, type, row) {
                return "<img src='" + data + "' style='width:50px;height:40px;cursor: pointer' " +
                    "onclick='$.showPicModal(\"" + data + "\")'> ";
            }
        }, {
            data: "coverId",
            render: function (data, type, row) {
                //var str = "<button id='showMap' onclick='$.showMap(" + row.longitude + "," + row.latitude + "," + data + ")' class='btn  btn-primary  btn-xs btn-flat' title='地图位置'><i class='glyphicon glyphicon-map-marker'></i></button> "
                var str = row.coverProvince + " " + row.coverCity + " " + row.coverArea;
                return str;
            }
        }, {
            data: "coverRegionId"
        }, {
            data: "coverOrgName"
        }, {
            data: "coverCreatorName"
        }, {
            data: "coverInstallTime",
            render: function (data, type, row) {
                return data.substring(0, 10);
            }
        }, {
            data: "coverId",
            render: function (data, type, row) {
                return "<button class='btn btn-primary btn-xs btn-flat' onclick='$.coverDetails (" + JSON.stringify(row) + ",0)' title='窨井详情'>点击查看</button>"
            }
        }, {
            data: "coverId",
            render: function (data, type, row) {
                var button = "";
                //1可上报
                if (row.reportStatus == 1) {
                    button += "<button class='btn btn-primary btn-xs btn-flat' onclick='$.sureCover(" + data + ")' title='选择窨井'>" +
                        "<i class='glyphicon glyphicon-eye-open'></i>上报</button>";
                } else {
                    button += "<button class='btn btn-primary btn-xs btn-flat' disabled onclick='' title='该窨井在处理中，无法上报'>" +
                        "<i class='glyphicon glyphicon-eye-open'></i>上报</button>";
                }
                return button;
            }
        }],
        dom: "<'row'<'col-md-12'><'#reportToolbar.col-md-12'>r>t<'row'>",
        initComplete: function () {
            // 下拉工具栏按钮的权限
            $("#reportToolbar").empty();
            var strToolBar = "<div style='margin-top: -10px' class='pull-right'><div class='btn-group'>" +
                "<button type='button' class='btn btn-primary btn-sm btn-flat'><i class='fa fa-cog'></i> 操作</button>" +
                "<button type='button' class='btn btn-primary btn-sm btn-flat dropdown-toggle' " +
                "data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>" +
                "<span class='caret'></span><span class='sr-only'>切换下拉</span></button>" +
                "<ul class='dropdown-menu'>" +
                "<li>" +
                "<button href='#' class='btn btn-primary btn-sm btn-flat btn-block' " +
                "onclick='gReportMainDT.ajax.reload(null, false);'><i class='fa fa-refresh'></i> 刷新</button>" +
                "</li>";

            strToolBar += "</ul></div> " +
                "<div class='input-group-sm' style='display:inline-block'>" +
                "<input id='roadName4S' onkeyup='$.getRoad(1);' type='text' class='form-control mysize' placeholder='路名'>" +
                "<select onchange='$.getRoad(2);' class='form-control mysize' id='startRoad4S'>" +
                "<option value=''>起/止</option>" +
                "</select>&nbsp;" +
                "<select class='form-control mysize' id='endRoad4S'>" +
                "<option value=''>止/起</option>" +
                "</select>&nbsp;</div>" +
                "<div class='input-group input-group-sm'>" +
                "<span class='input-group-btn'>" +
                "<button id='reportSearch' class='btn btn-primary btn-flat' type='button' onclick='$(this).searchReportDT()'>" +
                "<i class='fa fa-search'></i></button></span></div></div>";
            $("#reportToolbar").append(strToolBar);

            $.getRoad(1);

        },
        processing: true,
        serverSide: true,
        ordering: false,
        select: false,
        autoFill: true,
        bDestroy: true,
        displayLength: 20,
        lengthMenu: [[5, 10, 15, 20, 50, 100, 150, -1], [5, 10, 15, 20, 50, 100, 150, "All"]],
        language: {
            url: "zh_cn.json"
        },
        fnDrawCallback: function () {// 序号自增回调函数
            var api = this.api();
            var startIndex = api.context[0]._iDisplayStart;
            api.column(0).nodes().each(function (cell, i) {
                cell.innerHTML = startIndex + i + 1;
            });
        }
    });

    $("#coverDTModalLabel").text("窨井选择");
    $("#coverDTModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
    //隐藏故障上报modal
    $("#addFaultModal").hide();

};
$.closeCoverDTModal = function () {
    $("#coverDTModal").hide();
    $("#addFaultModal").show();
};

$.getRoad = function (type) {
    var id = "endRoad4S";
    var url = "../rds_coverFault/getSectionByStartRoad";
    var roadName = $("#startRoad4S").find("option:selected").val();
    if (type == 1) {
        url = "../rds_coverFault/getStartRoad";
        roadName = "";
        id = "startRoad4S";
    }
    $.ajax({
        url: url,
        type: "POST",
        async: false,
        data: {
            "roadName": roadName,
            "actorId": actorId,
            "orgId": gUserLoginResult.orgId
        },
        success: function (msg) {
            if (msg != null && typeof(msg) != "undefined") {
                if (msg.isSuccess == true) {
                    var roadNames = msg.jsonData;
                    $("#" + id).empty();
                    if (roadNames.length != 0) {
                        orgDataFlag = 0;
                        $("#" + id).append("<option value=''>起/止</option>");
                        for (var i = 0; i < roadNames.length; i++)
                            $("#" + id).append("<option value='" + roadNames[i] + "'>" +
                                roadNames[i] + "</option>");
                    }
                    if (type == 1) {
                        $.getRoad(2);
                    }
                } else {
                    $.alert("获取监管单位数据失败", 2);
                }
            }
        }
    })
};
$("#startRoad4S").change(function () {
    $.getRoad(0);
});

// report搜索框查询操作
$.fn.searchReportDT = function () {
    roadName4S = $("#roadName4S").val();
    startRoad4S = $("#startRoad4S").val();
    endRoad4S = $("#endRoad4S").val();
    gReportMainDT.search($("#startRoad4S").val()).draw();
};

//上报故障
$.reportCoverFault = function () {
    if ($("#addFault_address").text() == "" && $("#addFault_roadName").text() == "") {
        $.alert("请选择窨井", 2);
    } else if ($("#addFault_faultReason").val() == "") {
        $.alert("请填写故障原因", 2);
    } else if ($("#addFault_faultReason").val().length > 200) {
        $.alert("故障原因字数不能超过200", 2);
    } else {
        $("#reportBtn").attr("disabled", true);
        $.ajax({
            url: "../rds_coverFault/reportCoverFault",
            type: "post",
            dataType: "json",
            data: {
                "coverId": $("#addFault_coverId").val(),
                "coverFaultCreatorId": gUserLoginResult.userId,
                "coverFaultLevel": $("#addFault_faultLevel").val(),
                "coverFaultType": $("#addFault_faultType").val(),
                "coverFaultPhoto": $("#addFault_faultPhoto").attr("src"),
                "coverFaultReason": $("#addFault_faultReason").val(),
                "coverMoney": $("#addFault_money").val(),
                "coverOrgId": $("#addFault_coverOrgId").val(),
                "coverMainOrgId": $("#addFault_coverMainOrgId").val()
            },
            success: function (msg) {
                if (msg != null && typeof (msg) != "undefined") {
                    if (msg.isSuccess == true) {
                        $.alert("申报成功，等待内部审核", 1);
                        gMainDT.ajax.reload(null, false);
                        $.closeAddFaultModal();
                    } else {
                        $.alert("系统错误", 2);
                    }
                } else {
                    $.alert('系统错误，请联系管理员', 2);
                }
            },
            error: function () {
                $("#reportBtn").attr("disabled", false);
                $.alert("系统错误！", 4);
            }
        });
    }
};


//关闭审核模态框
$.closeAuditModal = function () {
    $("#audit_faultFeedback").val("");
    $("#auditModal").modal("hide");
};

//关闭窨井信息modal
$.closeDetailInfoModal = function () {
    solarEId = 0;
    $("#detail_reportbtn").css("display", "none");
    $("#detailInfoModal").modal("hide");
};

// 关闭添加故障modal
$.closeAddFaultModal = function () {
    $("#addFault_faultLevel").val(1);
    $("#addFault_faultType").val(0);
    $("#addFault_faultPhoto").attr("src", "../images/default_photo.png");
    $("#addFault_roadName").html("");
    $("#addFault_address").html("");
    $("#addFault_money").val("");
    $("#addFault_faultReason").val("");

    $("#addFault_coverId").val("");
    $("#addFault_coverOrgId").val("");
    $("#addFault_coverMainOrgId").val("");
    $("#addFault_coverFaultId").val("");

    $("#addFault_money").attr("disabled", false);
    $("#addFault_faultType").attr("disabled", false);
    $("#addFault_faultLevel").attr("disabled", false);
    $("#addFault_faultReason").attr("disabled", false);
    $("#addFault_faultPhoto").attr("onclick", "$.openUpPic()");
    $("#reportBtn").show();
    $("#updateBtn").hide();
    $("#addFault_DTBtn").show();
    $("#addFault_signMapBtn").show();

    $("#addFaultModal").modal("hide");
};

//关闭审核模态框
$.closeShowModal = function () {
    $("#audit_faultFeedback").val("");
    $("#auditModalLabel").modal("hide");
};

//关闭地图选择
$.closeSelectMap = function () {
    $("#selectMap").modal("hide");
    $("#addFaultModal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });
};

// 打开上传modal框
$.openUpPic = function () {
    $("#upPictureModal").modal({
        backdrop: 'static',
        keyboard: true,
        show: true
    });
};

// 关闭上传modal框
$.closeUpPhModal = function () {
    $("#upPictureModal").modal("hide");
    $("#ossfile").empty();
    clearOssData();
};

//获取图片信息
$.doneUpPhoto = function () {
    var fileInfo = getOssFileInfo();
    fileUrl = fileInfo[0].fileUrl;
    $("#addFault_faultPhoto").attr("src", fileUrl);
    $.closeUpPhModal();
};

//判断文件类型(在需要的js文件添加，文件名务必保持一致)
function judgeFileType(suffix) {
    //图片文件
    if (!(suffix == ".jpg" || suffix == ".JPG" || suffix == ".png" || suffix == ".PNG" ||
            suffix == ".jpeg" || suffix == ".JPEG" || suffix == ".gif" || suffix == ".GIF" ||
            suffix == ".bmp" || suffix == ".BMP")) {
        alert("请选择图片文件！");
        return false;
    }
}

//限制金额输入为0.00
function onlyNumber(obj) {

    //得到第一个字符是否为负号
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和.
    obj.value = obj.value.replace(/[^\d\.]/g, '');
    //必须保证第一个为数字而不是.
    obj.value = obj.value.replace(/^\./g, '');
    //保证只有出现一个.而没有多个.
    obj.value = obj.value.replace(/\.{2,}/g, '.');
    //保证.只出现一次，而不能出现两次以上
    obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
    //只能输入两位小数
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
    //如果第一位是负号，则允许添加
    if (t == '-') {


    }

}